/**
 * @file   irenderer.h
 * @Author Alexandre Chassany (alexandre.chassany@gmail.com)
 * @date   March 2011
 * @brief  Base interface for renderer
 *
 * Poum-tchak is a free sound manipulation and synthesis, 
 * real-time and interactive music-clip rendering.
 *
 * Copyright (C) 2011  Chassany Alexandre and Gonzalez Antoine.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * he Free Software Foundation, either version 3 of the License, or
 * at your option) any later version.
 *
 * is program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

template<int Type>
inline OpenGLBuffer<Type>::OpenGLBuffer(unsigned long count, unsigned int buffer) 
:IBufferBase(count)
,buffer_(buffer)
{
}

template<int Type>
inline OpenGLBuffer<Type>::~OpenGLBuffer()
{
  if(buffer_)
	glDeleteBuffersARB(1, &buffer_);
}

template<int Type>
inline unsigned int OpenGLBuffer<Type>::getBuffer() const
{
    return buffer_;
}

template<int Type>
inline void*OpenGLBuffer<Type>::lock(unsigned long offset, unsigned long size, unsigned long flags)
{
  glBindBufferARB(Type, buffer_);
  unsigned char* buffer = reinterpret_cast<unsigned char*>(glMapBufferARB(Type, getOpenglLockFlags(flags)/*GL_WRITE_ONLY_ARB*/));
  
  return buffer + offset;
}

template<int Type>
inline void OpenGLBuffer<Type>::unlock()
{
  glUnmapBufferARB(Type);
}
